/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.opshowcase.errorsreporting.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;

import fr.openparts.opshowcase.errorsreporting.client.presenter.ErrorsReportingPresenter;
import fr.openparts.opshowcase.errorsreporting.client.resources.ErrorsReportingResources;

/**
 * View of General Module of Errors Reporting for OpenParts Showcase.
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 30 March 2011
 */
public class ErrorsReportingView extends Composite {

    interface ErrorsReportingViewUiBinder extends UiBinder<Widget, ErrorsReportingView> {}
    private static ErrorsReportingViewUiBinder uiBinder = GWT.create(ErrorsReportingViewUiBinder.class);

    protected ErrorsReportingPresenter presenter;

    @UiField
    protected ErrorsReportingResources resources;
    
    @UiField
    protected Button unknownCommandButton;
    @UiField
    protected Label unknownCommandLabel;
    @UiField
    protected Button loadTimeoutButton;
    @UiField
    protected Label loadTimeoutLabel;
    @UiField
    protected Button noSuchView1Button;
    @UiField
    protected Label noSuchView1Label;
    @UiField
    protected Button noSuchView2Button;
    @UiField
    protected Label noSuchView2Label;
    @UiField
    protected Button noSuchSlotButton;
    @UiField
    protected Label noSuchSlotLabel;
    @UiField
    protected Button missingMandatoryParamButton;
    @UiField
    protected Label missingMandatoryParamLabel;
    @UiField
    protected Button noSuchServiceButton;
    @UiField
    protected Label noSuchServiceLabel;
    @UiField
    protected Button preCommandFailedViewButton;
    @UiField
    protected Label preCommandFailedViewLabel;
    @UiField
    protected Button preCommandFailedEventButton;
    @UiField
    protected Label preCommandFailedEventLabel;
    @UiField
    protected Button noSuchSlotIdInThePageViewButton;
    @UiField
    protected Label noSuchSlotIdInThePageViewLabel;
    @UiField
    protected Button givenIdIsNotASlotViewButton;
    @UiField
    protected Label givenIdIsNotASlotViewLabel;
    @UiField
    protected Button noViewAttachedToProxyButton;
    @UiField
    protected Label noViewAttachedToProxyLabel;
    
    @UiField
    protected LayoutPanel viewContainer;
    
    @UiField
    protected FlowPanel dummyContainer;
    
    /**
     * Constructor.
     */
    public ErrorsReportingView(final ErrorsReportingPresenter presenter) {
        initWidget(uiBinder.createAndBindUi(this));
        resources.style().ensureInjected();
        this.presenter = presenter;
        presenter.loadSubView(viewContainer);
    }
    
    @UiHandler("unknownCommandButton")
    public void unknownCommand(final ClickEvent event) {
        presenter.generateUnknownCommandErrorMessage(unknownCommandLabel);
    }

    @UiHandler("loadTimeoutButton")
    public void loadTimeout(final ClickEvent event) {
        presenter.generateLoadTimeoutErrorMessage(loadTimeoutLabel);
    }
    
    @UiHandler("noSuchView1Button")
    public void noSuchView1(final ClickEvent event) {
        presenter.generateNoSuchView1ErrorMessage(noSuchView1Label);
    }
    
    @UiHandler("noSuchView2Button")
    public void noSuchView2(final ClickEvent event) {
        presenter.generateNoSuchView2ErrorMessage(noSuchView2Label);
    }
    
    @UiHandler("noSuchSlotButton")
    public void noSuchSlot(final ClickEvent event) {
        presenter.generateNoSuchSlotErrorMessage(noSuchSlotLabel);
    }
    
    @UiHandler("missingMandatoryParamButton")
    public void missingMandatoryParam(final ClickEvent event) {
        presenter.generateMissingMandatoryParamErrorMessage(dummyContainer, missingMandatoryParamLabel);
    }
    
    @UiHandler("noSuchServiceButton")
    public void noSuchService(final ClickEvent event) {
        presenter.generateNoSuchServiceErrorMessage(noSuchServiceLabel);
    }
    
    @UiHandler("preCommandFailedViewButton")
    public void preCommandFailedView(final ClickEvent event) {
        presenter.generatePreCommandFailedViewErrorMessage(preCommandFailedViewLabel);
    }
    
    @UiHandler("preCommandFailedEventButton")
    public void preCommandFailedEvent(final ClickEvent event) {
        presenter.generatePreCommandFailedEventErrorMessage(preCommandFailedEventLabel);
    }
    
    @UiHandler("noSuchSlotIdInThePageViewButton")
    public void noSuchSlotIdInThePageView(final ClickEvent event) {
        presenter.generateNoSuchSlotIdInThePageViewErrorMessage(noSuchSlotIdInThePageViewLabel);
    }
    
    @UiHandler("givenIdIsNotASlotViewButton")
    public void givenIdIsNotASlotView(final ClickEvent event) {
        presenter.generateGivenIdIsNotASlotViewErrorMessage(dummyContainer, givenIdIsNotASlotViewLabel);
    }
    
    @UiHandler("noViewAttachedToProxyButton")
    public void noViewAttachedToProxy(final ClickEvent event) {
        presenter.generateNoViewAttachedToProxyErrorMessage(dummyContainer, noViewAttachedToProxyLabel);
    }
    
}
